package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
)

type NewsController struct {
	beego.Controller
}

func (c *NewsController) Get() {
	//c.TplName = "news.tpl"
	c.Ctx.WriteString("新闻中心")
}

func (c *NewsController) AddNews() {
	c.TplName = "news.tpl"
}

// 定义新闻表单结构体来接收请求参数
type NewsForm struct {
	Id      int    `form:"-"`
	Title   string `form:"title"`
	Content string `form:"content"`
}

func (c *NewsController) DoAddNews() {

	//title := c.GetString("title")
	//fmt.Printf("新闻标题 %v", title)

	news := NewsForm{}
	if err := c.ParseForm(&news); err == nil {
		fmt.Println("消息标题: " + news.Title)
		//c.Ctx.WriteString("新闻新增成功")

		c.Data["json"] = news
		c.ServeJSON()
	}
}
